﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Framework.Common.Reflection
{
    public static class MemberInfoExtention
    {
        public static object GetValue(this MemberInfo mi, Object param)
        {
            if (mi.MemberType == MemberTypes.Field)
            {
                var handler = DynamicMethodCompiler.CreateGetHandler((FieldInfo)mi);
                return handler(param);
            }
            else if (mi.MemberType == MemberTypes.Property)
            {
                var handler = DynamicMethodCompiler.CreateGetHandler((PropertyInfo)mi);
                return handler(param);
            }
            return null;
        }
    }

}
